package org.cwnuit.train.service;

import java.util.ArrayList;
import java.util.List;

import org.cwnuit.train.dao.RuleStimeDAO;
import org.cwnuit.train.dao.StimeDAO;
import org.cwnuit.train.dao.WtypeDAO;
import org.cwnuit.train.domain.RuleStime;
import org.cwnuit.train.domain.Stime;
import org.cwnuit.train.domain.Wtype;
import org.cwnuit.train.utils.PageModel;

@SuppressWarnings("all")
public class RuleStimeService {
	
	private StimeDAO stimeDAO = new StimeDAO();
	private WtypeDAO wtypeDAO = new WtypeDAO();
	private RuleStimeDAO rulestimeDAO = new RuleStimeDAO();
	
	
	public PageModel findByPage(int offset, int pagesize, String SQL) {
		PageModel pm = stimeDAO.findByPage(offset, pagesize, SQL);
		List<Stime> stimes = pm.getDatas();
		List<Stime> stimelist = new ArrayList();
		for(Stime stime:stimes){
			int wid = stime.getWid();
			Wtype wtype = wtypeDAO.findWtype("SELECT * FROM Wtype WHERE wid = " + wid);
			stime.setWtype(wtype);
			stimelist.add(stime);
		}
		pm.setDatas(stimelist);
		return pm;
	}
	public boolean addRuleStime(String SQL) {
		return rulestimeDAO.addRuleStime(SQL);
	}

	public boolean updateRuleStime(String SQL) {
		return rulestimeDAO.updateRuleStime(SQL);
	}
	
	public boolean deleteRuleStime(String SQL) {
		return rulestimeDAO.deleteRuleStime(SQL);
	}
	
	public RuleStime findRuleStime(String SQL) {
		return rulestimeDAO.findRuleStime(SQL);
	}
	public List<RuleStime> findRuleStimes(String SQL) {
		return rulestimeDAO.findRuleStimes(SQL);
	}
}
